package org.example.mall.admin.configuration.auth.check;

import lombok.extern.slf4j.Slf4j;
import org.example.mall.admin.configuration.auth.code.AbstractSendCodeHandler;
import org.example.mall.admin.configuration.auth.code.ScenesConst;
import org.example.mall.admin.constant.auth.AuthTypeConst;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 手机号码验证码登录检验
 *
 * @author hzq
 * @date 2021/12/10 14:43
 */
@Slf4j
@Component
public class PhoneCheckAuthHandler extends AbstractCheckAuthHandler {

    private static final List<String> SUPPORT_SCENES = new ArrayList<>(Arrays.asList(ScenesConst.LOGIN, ScenesConst.BIND));

    @Override
    public boolean supportType(String checkType) {
        return AuthTypeConst.PHONE.equals(checkType);
    }

    @Override
    public boolean supportScenes(String scenes) {
        return SUPPORT_SCENES.contains(scenes);
    }

    @Override
    protected Object getCode(String scenes, String principal) {
        return valueOperations.get(AbstractSendCodeHandler.generateKey(scenes, principal, AuthTypeConst.PHONE));
    }
}
